<?php
require_once("Includes/connection.php");
require_once("Includes/functions.php");
session_start();
if(isset($_SESSION['username'])){
	if(isset($_POST['submit'])){
		$query=sprintf("DELETE FROM polls WHERE id='%s'",$_POST['poll']);
		mysql_query($query);
	}
	if(isset($_POST['view'])){
		header('Location: poll_data.php?short_name='.$_POST['short_name']);
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css/main.css" />
<title>Q&A </title>
</head>
<body>
	<table id="header">
    <tr><td></td>
    <td colspan="2" style="width:1000px; text-align:center;">
    	<table><tr><td width="180">
    	<img src="images/logo_qanda.gif" height="80"/>
		</td><td>
        <h1 style="height:auto;">ACM RUM Q&A </h1>
		</td></tr></table>
    </td>
    <td></td></tr>
    <tr><td style="border-bottom:1px solid black;"></td><td style="width:180px;"></td><td style="border-bottom:1px solid black; width:813px;"></td><td style="border-bottom:1px solid black;"></td></tr>
    </table>
    <table id="container">
        <tr>
        <td style="border-left:1px solid black; border-right:1px solid black; width:176px; height:30px; padding-top:10px; padding-left:5px; background-color:#FC0;">
        <a href="home.php">Home</a>
        </td><td rowspan="6" style="border-right:1px solid #CCC; border-bottom:1px solid #CCC;  padding-top:15px;">
            <table id="main_content_view">
            	<tr>
                <th>ID</th>
				<th>Type</th>
				<th>Time Start</th>
				<th>Time End</th>
				<th>Name</th>
				<th>Short Name</th>
				<th>Registration Required</th>
				<th>Multiple Entries</th>
				<th>SMS Entries</th>
				<th>Web Entries</th>
                <th>View</th>
                <th>Delete</th>
                </tr>
            <?php			
			$query = sprintf("SELECT * FROM polls");
			$result = mysql_query($query);
			while($info = mysql_fetch_assoc($result)){
				echo '<tr>
				<td><a href="poll_data.php?short_name='.$info['short_name'].'">'.$info['id'].'</a></td>
				<td>'.$info['type'].'</td>
				<td>'.$info['time_start'].'</td>
				<td>'.$info['time_end'].'</td>
				<td><a href="poll_data.php?short_name='.$info['short_name'].'">'.$info['name'].'</a></td>
				<td>'.$info['short_name'].'</td>
				<td>'.$info['registration_required'].'</td>
				<td>'.$info['multiple_entries'].'</td>
				<td>'.$info['sms_entries'].'</td>
				<td>'.$info['web_entries'].'</td>
				<form action="view_polls.php" method="post">
				<input type="hidden" name="short_name" value="'.$info['short_name'].'">
				<td><input type="submit" name="view" value="View"/></td>
				</form>
				<form action="view_polls.php" method="post">
				<input type="hidden" name="poll" value="'.$info['id'].'">
				<td><input type="submit" name="submit" value="Delete"/></td></tr>
				</form>';
			}
			?>
            </table>
            </form>
        </td></tr>
        <tr><td style="border-left:1px solid black; border-right:1px solid black; width:176px; height:30px; padding-left:5px; background-color:#FC0;">
        <a href="create_poll.php">Create Poll</a>
        </td></tr>
        <tr><td style="border:1px solid black; border-right:none; background-color:#FFF; width:176px; height:30px; padding-left:5px;">
        <a href="view_polls.php">View Polls</a>
        </td></tr>
        <tr><td style="border-left:1px solid black; border-right:1px solid black; width:176px; height:30px; padding-left:5px; background-color:#FC0;">
        <a href="manage_accounts.php">Manage Accounts</a>
        </td></tr>
        <tr><td style="border-left:1px solid black; border-right:1px solid black; width:176px; height:30px; padding-left:5px; background-color:#FC0;">
        <a href="index.php">Logout</a>
        </td></tr>
        <tr><td style="border:1px solid black; border-top:none; width:176px; padding-left:5px; background-color:#FC0;">
        </td>
        </tr>
    </table>
</body>
</html>
<?php 
}
else{
	header('Location: index.php');
}
?>